


// 

let axios = require("axios");
let fs = require("fs");
const proxy = {
    host:"127.0.0.1",
    port: "7891",
    protocol: "http"
};
let headers = {
    accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7",
    cookie: "ipb_session_id=41682ef2211d381699a722378986d6e4; ipb_member_id=6722035; ipb_pass_hash=6f77e4c8018f782230ec66dc1c3f671c",
    referer: "https://e-hentai.org/",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "same-origin",
    "sec-fetch-user": "?1",
    "upgrade-insecure-requests": "1",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36"
}


;
(async() => {
    await fetchImg({url: "https://e-hentai.org/g/2290337/a8652ad8e0/"})
})();



async function sleep(time) {
    return new Promise((a) => {
        setTimeout(() => {
            a()
        }, time);
    })
}


async function fetchImg(props) {
    let ret = await axios.get(encodeURI(props.url), {
        headers,proxy
    })
   
    if(ret?.data) {
        fs.writeFileSync("./serch.html", ret.data)
        // let matchs = ret.data.match(/<td class="gl3c glname"(?:(?!<\/td>)[\w\W])+/ig);
        // if(matchs && matchs.length) {
        //     matchs = matchs.map((str, i) => {
        //         let ret = {}
        //         // <div class="glink">[Kimura Hidesato] Yorokobi no Senpou | The Vanguard of Pleasure (Ore,
        //         //     Higaisha) [English] [Must Be Endless Scanlations &amp; ebil trio]</div>
        //         ret.title = /<div class="glink">((?:(?!<\/div>)[\w\W])+)<\/div>/ig.exec(str)[1]
        //         ret.gts = str.match(/<div class="gt" title="[^"]+">([^<]+)<\/div>/ig).map(v => /<div class="gt" title="[^"]+">([^<]+)<\/div>/ig.exec(v)[1])
        //         // 解析url
        //         // 
        //         if(/<a href="https:\/\/e-hentai.org\/g\/[^/]+\/[^/]+\/">/.test(str)) {
        //             ret.url = /<a href="(https:\/\/e-hentai.org\/g\/[^/]+\/[^/]+\/)">/.exec(str)[1]
        //         }
                
        //         return ret
        //     })
        //     if(!fs.existsSync(`./searchs/${props.key}`)) {
        //         fs.mkdirSync(`./searchs/${props.key}`)
        //     }
        //     fs.writeFileSync(`./searchs/${props.key}/${props.page}.json`, JSON.stringify(matchs) )
        //     console.log("featch: " + props.page);
        //     await sleep(4000 + Math.random() * 1000)
        //     await searchDoc(props)
        //     return
        // }
    }
    
}